package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.Action;
import javax.swing.JCheckBoxMenuItem;

import com.mrogrape.notepad.activity.MainFrame;
import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.activity.entity.ViewSettings;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.resource.Settings;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class LineWrapMenuItemAction extends NotepadAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public LineWrapMenuItemAction(){

		super.putValue(Action.NAME, "Line Warp");
		super.putValue(Action.SHORT_DESCRIPTION, "Toggle line number visible.");
	}

	@Override
	public void actionPerformed(ActionEvent ae) {

		MainFrame frame = ViewContext.getMainFrame();
		JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
		ViewSettings settings = Settings.getSettings().getViewSettings();

		boolean selected = item.isSelected();
		settings.setLineWrap(selected);
		List<TextEditor> editors = frame.getAllTextEditors();
		for(TextEditor editor : editors){
			editor.setLineWrap(selected);
		}
	}
}
